import WebSocketClient from '../comm/websocket.js' 
import { useWsStore } from '@/stores/ws-module'

const wsUrls = ['/roboArm', '/moveCapture', '/history', '/tm', '/navigate', '/carrySystem']
const wsStore = useWsStore()

export const initWsObj = () => {
  wsUrls.map(url => {
    const ws = new WebSocketClient(url, (messages) => {
      wsStore.setWs(url, messages)
    })
    ws.connect()
  })  
}

export const initCarrySystem = () => {
  const url = '/carrySystem'
  const ws = new WebSocketClient(url, (messages) => {
    wsStore.setWs(url, messages)
  })
  ws.connect()
}

export const initNavigate = () => {
  const url = '/navigate'
  const ws = new WebSocketClient(url, (messages) => {
    wsStore.setArrToObj(url, messages)
  })
  ws.connect()
}

export const initTm = () => {
  const url = '/tm'
  const ws = new WebSocketClient(url, (messages) => {
    wsStore.setArrToObj(url, messages)
  })
  ws.connect()
  return ws
}

export const initCapture = () => {
  const url = '/moveCapture'
  const ws = new WebSocketClient(url, (messages) => {
    wsStore.setWs(url, messages)
  })
  ws.connect()
  return ws
}

export const initRoboArm = () => {
  const url = '/roboArm'
  const ws = new WebSocketClient(url, (messages) => {
    wsStore.setWs(url, messages)
  })
  ws.connect()
  return ws
}

export const initSlowTmWs = () => {
  const url = '/slow'
  const ws = new WebSocketClient(url, (messages) => {
    
    wsStore.setWs(url, messages)
  })
  ws.connect()
}

export const initTcLogsWs = () => {
  const url = '/history'
  const ws = new WebSocketClient(url, (messages) => {

    wsStore.setWs(url, messages)
  })
  ws.connect()
}

